var a = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        language: "",
        category: [],
        mainInfo: {},
        telephone: "",
        path: "",
        title: "",
        info: {},
        infoShow: !1,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        isShow: !1,
        store_member: [],
        store_room: [],
        micro_communities: [],
        get_recommend_goods: [],
        commentList: [],
        delivery_note: "",
        delivery_area: [ [ 116.403322, 39.920255 ] ],
        locations: [ 116.403322, 39.920255 ],
        delivery_status: 0,
        markers_2: [ {
            latitude: 23.099994,
            longitude: 113.32452,
            iconPath: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
            width: 20,
            height: 25,
            callout: {
                padding: "10rpx",
                borderRadius: "5rpx"
            }
        } ],
        polygons_2: [ {
            points: [],
            fillColor: "#FF88887F",
            strokeColor: "#FFF",
            strokeWidth: 2,
            zIndex: 1
        } ],
        delivery: {
            longitude: "113.324520",
            latitude: "23.099994"
        },
        delivery_amount: 0,
        is_open: 0,
        balanceTitle: "",
        member_balance: "",
        show_button: 0,
        show_qr_code: !1,
        tabList: [],
        menuList: [],
        tabName: 10,
        tabIndex: 0,
        isLoading: !1,
        qr_code: '',//门店收款码
        storeCodeShow: false,//门店收款码展示弹窗
    },
    onLoad: function(a) {
        if (a.scene) {
            var e = decodeURIComponent(a.scene);
            if (console.log(e, "scene"), e) {
                var i = [];
                i = e.split(",");
                for (var o = 0; o < i.length; o++) {
                    var s;
                    s = i[o].split("="), console.log(s), "store_id" == s[0] && this.setData({
                        store_id: s[1]
                    }), "mid" == s[0] && t._setMid(s[1]);
                }
            }
        }
        a.store_id && this.setData({
            store_id: a.store_id
        }), this.getStoreInfo(), this.getBalance(),this.getCode();

    },
    onCloseStore(){
      this.setData({
        storeCodeShow: false
      })
    },
    openStoreCode(){
      this.setData({
        storeCodeShow: true
      })
    },
    // 获取门店收款码
    getCode: function() {
      console.log('getCode',this.data.store_id)
      var s, e = this;
      s = t.getNetAddresss("HuanNiu.getCollectionCode"), 
      s += "&store_id=" + this.data.store_id + "&type=2", t._getNetWork({
          url: s,
          success: function(o) {
              var t = o.data;
              1 == t.result ? e.setData({
                  qr_code: t.data 
              }) : wx.showToast({
                  icon: "none",
                  title: t.msg,
                  duration: 1500
              });
          },
          fail: function(o) {
              console.log(o);
          }
      });
  },
    toStoreBalance: function(a) {
        "balance" == a.currentTarget.dataset.key ? wx.navigateTo({
            url: "/packageI/independenceBalance/storeBalance/balance_recharge?store_id=" + this.data.store_id
        }) : wx.navigateTo({
            url: "/packageI/independenceBalance/independenceBalance?store_id=" + this.data.store_id
        });
    },
    copybtn: function(a) {
        var t = a.currentTarget.dataset.wechat;
        wx.setClipboardData({
            data: t || "",
            success: function(a) {
                wx.showToast({
                    icon: "none",
                    title: "复制成功",
                    duration: 1e3
                });
            }
        });
    },
    chooseTab: function(a) {
        var t = a.currentTarget.dataset.item;
        if (this.setData({
            tabIndex: a.currentTarget.dataset.index,
            tabName: t.value
        }), 50 == this.data.tabIndex) wx.navigateTo({
            url: "/packageD/ActivityDetail/ActivityDetail?id=" + t.id + "&store_id=" + this.data.store_id
        }); else if ("赛车成绩" == this.data.tabIndex) wx.navigateTo({
            url: "/packageH/turmaroundTime/turmaroundIndex/turmaroundIndex?id=" + this.data.store_id
        }); else if (80 == t.value) return void wx.navigateTo({
            url: "/packageF/storeSign/storeSign/storeSign?id=" + this.data.store_id
        });
        this.getTabsData();
    },
    getTabsData: function() {
        var e = this;
        if (this.data.menuList[this.data.tabIndex].url) if (this.data.menuList[this.data.tabIndex].list.length > 0) this.data.isLoadMore = this.data.menuList[this.data.tabIndex].isLoadMore; else {
            var i = 1, o = [];
            this.data.isLoading = !0;
            var s = t.getNetAddresss(this.data.menuList[this.data.tabIndex].url);
            t._postNetWork({
                url: s,
                data: {
                    page: 1,
                    store_id: this.data.store_id
                },
                success: function(t) {
                    var s, n = t.data;
                    1 == n.result ? (20 == e.data.tabName ? (i = n.data.last_page, o = e.setCommunities(n.data.data)) : 40 == e.data.tabName ? o = n.data : null !== (s = n.data) && void 0 !== s && s.data ? (i = n.data.last_page, 
                    o = n.data.data) : console.log("getTabsData()::error", n.data), e.data.isLoadMore = !0, 
                    e.data.menuList[e.data.tabIndex].isLoadMore = !0, e.data.menuList[e.data.tabIndex].total_page = i, 
                    e.data.menuList[e.data.tabIndex].total_page || (e.data.menuList[e.data.tabIndex].total_page = 0), 
                    e.setData(a({}, "menuList[" + e.data.tabIndex + "].list", o))) : wx.showToast({
                        icon: "none",
                        title: n.msg,
                        duration: 1e3
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        } else console.log("menu_list该标签没有返回请求api");
    },
    setCommunities: function(a) {
        var t = [];
        return a.map(function(a) {
            t.push({
                id: a.id,
                title: a.title,
                praise_num: a.praise_num,
                has_one_stick_user: {
                    avatar: a.user_avatar,
                    nickname: a.user_nickname
                },
                has_many_image: [ {
                    url: a.image,
                    stick_id: a.id
                } ]
            });
        }), t;
    },
    toCard: function(a) {
        var t = a.currentTarget.dataset.cardid;
        t && wx.navigateTo({
            url: "/packageB/member/business_card/BusinessCard/BusinessCard?card_id=" + t + "&mark=card"
        });
    },
    gomenphone: function(a) {
        var t = a.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },
    toGood: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + t
        });
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {
        this.setData({
            tabName: 10,
            tabIndex: 0
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareTimeline: function() {
        return this._share(), {
            title: this.data.title,
            path: this.data.path,
            imageUrl: this.data.imageUrl
        };
    },
    onShareAppMessage: function() {
        return this._share(), {
            title: this.data.title,
            path: this.data.path,
            imageUrl: this.data.imageUrl
        };
    },
    getStore: function(a) {
        this.setData({
            mainInfo: a,
            telephone: a.store_mobile,
            commentList: a.comment
        });
    },
    _share: function() {
        var a = wx.getStorageSync("yz_uid"), t = this.data.mainInfo.store_name || "", e = "/packageC/o2o/HomeSeller/HomeSeller?share_tag=2&mid=" + a + "&store_id=" + this.data.store_id;
        this.setData({
            title: t,
            path: e,
            imageUrl: this.data.mainInfo.store_thumb
        });
    },
    goToAdress: function() {
        var a = this.data.mainInfo.lat, e = this.data.mainInfo.lng, i = this.data.mainInfo.store_name, o = t.BMapTransqqMap(parseFloat(e), parseFloat(a));
        wx.openLocation({
            latitude: o.lat,
            longitude: o.lng,
            scale: 18,
            name: i
        });
    },
    gophone: function() {
        var a = this.data.mainInfo.store_mobile;
        wx.makePhoneCall({
            phoneNumber: a
        });
    },
    goToShop: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + this.data.store_id + "&fromHome=1"
        });
    },
    goToCrash: function() {
        wx.navigateTo({
            url: "/packageC/cashier/cashier_pay/cashier_pay?store_id=" + this.data.store_id + "&fromHome=1"
        });
    },
    getStoreInfo: function() {
        var a = this, e = t.getNetAddresss("plugin.store-cashier.frontend.store.get-store-info.get-the-provider");
        t._getNetWork({
            url: e,
            data: {
                store_id: this.data.store_id,
                url: ""
            },
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    if (i.data.store_decorate && i.data.store_decorate.datas) return void wx.redirectTo({
                        url: "/packageG/o2o/HomeSeller/HomeSeller?store_id=" + a.data.store_id
                    });
                    if (a.getStore(i.data.store_info), a.setTabsList(i.data.menu_list), a.setData({
                        isShow: !0,
                        get_recommend_goods: i.data.get_recommend_goods
                    }), t._isTextEmpty(i.data.store_information) || (i.data.store_information = i.data.store_information.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block"'), 
                    a.setData({
                        info: i.data.store_information,
                        infoShow: !0
                    })), a.data.mainInfo.store_delivery && 1 == a.data.mainInfo.store_delivery.delivery_status) {
                        a.setData({
                            delivery_status: 1,
                            delivery_note: a.data.mainInfo.store_delivery ? a.data.mainInfo.store_delivery.delivery_note : "",
                            delivery_amount: a.data.mainInfo.store_delivery ? a.data.mainInfo.store_delivery.delivery_amount : 0
                        });
                        var o = a.data.mainInfo.store_delivery ? a.data.mainInfo.store_delivery.delivery_area : [], s = a.data.mainInfo.store_delivery ? a.data.mainInfo.store_delivery.locations : [], n = [];
                        if (o.length > 0 && o.forEach(function(a, t) {
                            n.push([ Number(a.R), Number(a.Q) ]);
                        }), a.setData({
                            delivery_area: n,
                            locations: [ Number(s.longitude).toFixed(6), Number(s.latitude).toFixed(6) ]
                        }), a.data.locations && a.data.locations.length > 0 && a.setData({
                            "markers_2[0].longitude": a.data.locations[0],
                            "markers_2[0].latitude": a.data.locations[1],
                            "delivery.longitude": a.data.locations[0],
                            "delivery.latitude": a.data.locations[1]
                        }), a.data.delivery_area && a.data.delivery_area.length > 0) {
                            for (var r = [], d = 0; d < a.data.delivery_area.length; d++) r.push({
                                longitude: a.data.delivery_area[d][0],
                                latitude: a.data.delivery_area[d][1]
                            });
                            a.setData({
                                "polygons_2[0].points": r
                            });
                        }
                    }
                } else wx.showToast({
                    title: i.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    setTabsList: function(a) {
        var t = [], e = [];
        a.forEach(function(a, i) {
            a.is_show && (t.push(a), e.push({
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: [],
                url: a.api
            }));
        }), this.setData({
            tabList: t,
            menuList: e
        });
    },
    gopage: function(a) {
        var t = a.currentTarget.dataset.status, e = a.currentTarget.dataset.id, i = a.currentTarget.dataset.backid;
        1 == t ? wx.navigateTo({
            url: "/packageD/directSeeding/livePage/livePage?id=" + e + "&playerType=live"
        }) : 2 == t ? wx.navigateTo({
            url: "/packageD/directSeeding/livePage/livePage?id=" + e + "&playerType=video&backid=" + i
        }) : 3 == t && wx.navigateTo({
            url: "/packageD/directSeeding/foreshow/foreshow?id=" + e
        });
    },
    _getMoreData: function() {
        var e = this, i = this;
        if (this.data.menuList[this.data.tabIndex].isLoadMore = !1, this.data.isLoadMore = !1, 
        !(this.data.menuList[this.data.tabIndex].page >= this.data.menuList[this.data.tabIndex].total_page)) {
            var o = [], s = {
                store_id: this.data.store_id
            };
            this.data.menuList[this.data.tabIndex].page = this.data.menuList[this.data.tabIndex].page + 1, 
            s.page = this.data.menuList[this.data.tabIndex].page;
            var n = t.getNetAddresss(this.data.menuList[this.data.tabIndex].url);
            t._postNetWork({
                url: n,
                showToastIn: !1,
                data: s,
                success: function(t) {
                    var s = t.data;
                    if (1 != s.result) return e.data.menuList[e.data.tabIndex].page = e.data.menuList[e.data.tabIndex].page - 1, 
                    e.data.menuList[e.data.tabIndex].isLoadMore = !1, void (e.data.isLoadMore = !1);
                    i.data.isLoadMore = !0, 20 == e.tabName ? o = e.setCommunities(s.data) : 40 == e.tabName ? o = s : s && s.data ? o = s.data : console.log("getTabsData()::error", s), 
                    e.setData(a({}, "menuList[" + e.data.tabIndex + "].list", e.data.menuList[e.data.tabIndex].list.concat(o)));
                },
                fail: function(a) {
                    console.log(a.msg);
                }
            });
        }
    },
    goToCode: function() {
        wx.navigateTo({
            url: "/packageC/cashier/cashier_qr/cashier_qr?name=storeBalance&store_id=" + this.data.store_id
        });
    },
    getBalance: function() {
        var a = this, e = t.getNetAddresss("plugin.store-cashier.frontend.store.balance.setting.index");
        t._postNetWork({
            url: e,
            data: {
                store_id: this.data.store_id
            },
            success: function(t) {
                console.log(t);
                var e = t.data;
                a.setData({
                    is_open: e.data.is_open,
                    balanceTitle: e.data.title,
                    member_balance: e.data.member_balance,
                    show_button: e.data.show_button,
                    show_qr_code: e.data.show_qr_code
                });
            },
            fail: function(a) {
                wx.showToast({
                    title: a.data.msg,
                    duration: 1e3,
                    icon: "none"
                });
            }
        });
    }
});